<?php

/**
 * This is the model class for table "xman_bug_list".
 *
 * The followings are the available columns in table 'xman_bug_list':
 * @property integer $bug_list_id
 * @property integer $bug_project_id
 * @property string $bug_list_name
 * @property string $bug_list_description
 *
 * The followings are the available model relations:
 * @property Bug[] $bugs
 * @property Project $bugProject
 */
class BugList extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return BugList the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'xman_bug_list';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('bug_project_id, bug_list_name', 'required'),
			array('bug_project_id', 'numerical', 'integerOnly'=>true),
			array('bug_list_name', 'length', 'max'=>50),
			array('bug_list_description', 'safe'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('bug_list_id, bug_project_id, bug_list_name, bug_list_description', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
			'bugs' => array(self::HAS_MANY, 'Bug', 'bug_list_id'),
			'bugProject' => array(self::BELONGS_TO, 'Project', 'bug_project_id'),
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'bug_list_id' => 'Bug List',
			'bug_project_id' => 'Bug Project',
			'bug_list_name' => 'Bug List Name',
			'bug_list_description' => 'Bug List Description',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('bug_list_id',$this->bug_list_id);
		$criteria->compare('bug_project_id',$this->bug_project_id);
		$criteria->compare('bug_list_name',$this->bug_list_name,true);
		$criteria->compare('bug_list_description',$this->bug_list_description,true);

		return new CActiveDataProvider(get_class($this), array(
			'criteria'=>$criteria,
		));
	}
	
public function getBugList($projectID){
		/** Get buglist in each project
		 */
	    $BugList = $this->findAll('bug_project_id',$projectID);
	  foreach($BugList as $item){
	     //place code get BUg in List here 
	     $id=$item->bug_list_id;
	    $item["bug"]= Bug::model()->getAllBug($id);
	  }  
	  return $BugList;
	}
}